import allure
from appium.webdriver.common.appiumby import AppiumBy

from base.wework_app import Wework


class SearchPage(Wework):
    """
    搜索页面
    """
    # 搜索栏
    _search_input = (AppiumBy.XPATH, "//*[@text='搜索']")
    # 查询结果
    _search_result = (AppiumBy.XPATH, "//androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup")
    # 联系人信息按钮
    _member_info_btn = (
        AppiumBy.XPATH,
        "//androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup/android.widget.ImageView[2]")

    @allure.step("搜素指定联系人")
    def search_member(self, name):
        """
        搜索联系人
        :param name: 成员姓名
        :return:
        """
        # 输入人名
        self.find_ele(self._search_input).send_keys(name)
        return self

    @allure.step("点击联系人名称右侧按钮，跳转到添加成员页面")
    def goto_member_info_page(self):
        """
        跳转到成员信息页面
        :return: 成员信息 page
        """
        from page.member_info_page import MemberInfoPage

        self.find_ele(self._member_info_btn).click()

        return MemberInfoPage(self.driver)

    @allure.step("返回查询结果")
    def get_result(self):
        """
        返回查询结果
        :return:
        """
        return self.find_eles(self._search_result)

    @allure.step("返回通讯录页面")
    def goto_address_list_page(self):
        """
        返回通讯录
        :return:
        """
        from page.address_list_page import AddressListPage
        self.go_back(1)
        return AddressListPage(self.driver)
